package com.shop.www.dao.Impl;

import com.shop.www.dao.CartItemDAO;
import com.shop.www.model.CartItem;
import com.shop.www.model.User;
import com.shop.www.ssm.BasicDao;

import java.util.List;

public class CartItemDAOImpl extends BasicDao implements CartItemDAO {
    @Override
    public void addcartItem(CartItem cartItem) {
        String sql =("insert into cartitem values(0,?,?,?)");
        update(sql,cartItem.getCommodity_ID(),cartItem.getBuycount(),cartItem.getUser_ID());

    }

    @Override
    public void updatecartItem(CartItem cartItem) {
        String sql =("update cartitem set buycount = ? where CartItem_ID = ?");
        update(sql,cartItem.getBuycount(),cartItem.getCartItem_ID());

    }

    @Override
    public List<CartItem> getCartItem(User user) {
        String sql =("select * from cartitem Where User_ID = ?");
        List<CartItem> list = querymany(sql,CartItem.class,user.getUser_ID());
        return list;

    }

    @Override
    public void delcartItem(CartItem cartItem) {
        String sql = ("delete from cartItem where cartitem_ID = ?");
        update(sql,cartItem.getCartItem_ID());
    }

    @Override
    public List getsellerlist(User user) {
        String sql =("SELECT c.user_ID FROM `cartitem` s  INNER JOIN `commodity` c ON s.commodity_ID = c.commodity_ID WHERE s.user_ID =? GROUP BY c.user_ID ;");
        List<User> list= querymany(sql,User.class,user.getUser_ID());
        return list;
    }
}
